package eerbaar.shared.service;

import java.util.HashMap;
import java.util.Map;

public class ServiceFactory {

    private static final Map<String, IService> map = new HashMap<String, IService>();

    @SuppressWarnings("unchecked")
    public static <T> T getService(Class<T> clazz) {
        assert (clazz != null);

        return (T) map.get(clazz.getName());
    }

    public static <T> void register(Class<T> clazz, IService service) {
        assert (clazz != null);

        if (map.containsKey(clazz)) {
            return;
        }

        map.put(clazz.getName(), service);
    }

}
